#include "repeater.h"

repeater::repeater()
{
    atk = 25;//攻击力
    hp = 300;//生命
    time = int(1.4 * 1000 / 33);//攻击间隔时间
    setMovie(":/new/prefix1/Repeater.gif");
}

void repeater::advance(int phase)
{
    if (!phase)
        return;
    update();
    if (hp <= 0)
        delete this;//生命值小于等于零，删除自身
    else if (++counter >= time)
    {
        counter = 0;
        QList<QGraphicsItem *> items = collidingItems();
        if (!collidingItems().isEmpty())
        {
            peashot *pe = new peashot(atk);
            pe->setX(x() + 32);
            pe->setY(y());
            scene()->addItem(pe);
            pe = new peashot(atk);
            pe->setX(x() + 64);
            pe->setY(y());
            scene()->addItem(pe);
            return;
        }
    }
}

bool repeater::collidesWithItem(const QGraphicsItem *other, Qt::ItemSelectionMode mode) const
{
    Q_UNUSED(mode)
    return other->type() == zombie::Type && qFuzzyCompare(other->y(), y());
}//判断是否与僵尸在同一行，是则发生碰撞
